package com.gkoudai.open.platform.common;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.util.UriComponentsBuilder;

import java.net.URI;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * @author : Amater
 * @date : 2024/10/28 17:01
 */
@Slf4j
public class StringCommon {
    public static final String PLACEHOLDER = "\\{\\}";
    public static final String ACCESS_TOKEN = "accessToken";
    public static final String URL_PREFIX = "wss://open-socket.gkoudai.com/socket.io/?transport=websocket&accessToken=";

    private StringCommon() {
    }

    public static String parseJsonString(Object object) {
        try {
            ObjectMapper objectMapper = new ObjectMapper();
            objectMapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
            return objectMapper.writeValueAsString(object);
        } catch (Exception e) {
            log.error("Object to json string  error", e);
            return null;
        }
    }

    public static String buildString(String msg, Object... placeHolders) {
        for (Object placeHolder : placeHolders) {
            msg = msg.replaceFirst(PLACEHOLDER, placeHolder.toString());
        }
        return msg;
    }

}


